import request from '@/utils/request';

const api = {
	WX_ACCESS_TOKEN: '/app/wx_access_token',
	WX_PHONE_LOGIN: '/app/wx_phone_login',
	TOKEN_LOGIN: ''
}

export async function loginCode() {
	return new Promise((resolve, reject) => {
		uni.login({
			provider: 'weixin',
			success(res) {
				resolve(res.code);
			},
			fail(err) {
				reject(err);
			}
		});
	});	
	
}

export async function wxAccessToken() {
	return request.get(api.WX_ACCESS_TOKEN);
}

export async function wxPhoneLogin(accessToken, code) {
	let params = {
		accessToken: accessToken,
		code: code
	};
	return request.get(api.WX_PHONE_LOGIN, params);
}
 
 export async function tokenLogin(token) {
 	let params = {
 		token: token
 	};
 	return request.post(api.TOKEN_LOGIN, params);
 }